<?php
class presale_mdl_orders extends ome_mdl_orders{

    public function table_name($real = false){
        if($real){
            $table_name = 'sdb_ome_orders';
        }else{
            $table_name = 'orders';
        }
        return $table_name;
    }

    public function get_schema(){
        return app::get('ome')->model('orders')->get_schema();
    }


    function _filter($filter,$tableAlias=null,$baseWhere=null){
        $where = 1;

        if ($filter['shop_pay'] && in_array($filter['shop_pay'],array('1','2'))){
            $orderIds = $this->getorderExtend($filter['shop_pay']);
            if($orderIds){
                $where .= '  AND order_id IN (\''.implode('\',\'', $orderIds).'\')';

            }
            unset($filter['shop_pay']);
        }

        return $where ." AND ".parent::_filter($filter,$tableAlias,$baseWhere);
    }


    function getorderExtend($shop_pay){

        $extendObj = app::get('ome')->model('order_extend');
        if($shop_pay == 1){
            $order_list = $extendObj->db->select("SELECT e.order_id FROM sdb_ome_order_extend as e LEFT JOIN sdb_ome_orders as o ON e.order_id=o.order_id WHERE o.order_type='presale' AND presale_pay_status='1'");
        }

        if($shop_pay == 2){
            $order_list = $extendObj->getList('order_id',array('presale_pay_status'=>2));
        }


        if($order_list){
            foreach ($order_list as $orders){
                $orderIds[] = $orders['order_id'];
            }
        }
        return $orderIds;
    }
}



?>